Return to start page
Systems/Character/Struct Quest.j
1 library AStructSystemsCharacterQuest requires optional ALibraryCoreDebugMisc, ALibraryCoreEnvironmentSound, AStructCoreGeneralVector, ALibraryCoreStringConversion, AStructSystemsCharacterAbstractQuest
2
3 struct AQuest extends AAbstractQuest
4 //static start members
5 private static boolean useQuestLog
6 private static string updateSoundPath
7 //dynamic members
8 private AIntegerVector m_questItems
9 private string m_iconPath
10 private string m_description
11 //members
12 private quest m_questLogQuest
13
14 ///! runtextmacro optional A_STRUCT_DEBUG("\"AQuest\"")
15
16 //dynamic members
17
18 public method questItem takes integer index returns AQuestItem
19 return this.m_questItems[index]
20 endmethod
21
22 public method setIconPath takes string iconPath returns nothing
23 debug if (not thistype.useQuestLog) then
24 debug call this.print("setIconPath() was called (quest log is disabled).")
25 debug endif
26 set this.m_iconPath = iconPath
27 call QuestSetIconPath(this.m_questLogQuest, iconPath)
28 endmethod
29
30 public method iconPath takes nothing returns string
31 return this.m_iconPath
32 endmethod
33
34 /// No flash, just when you change the state!
35 /// Description also is not used as start property because you do not always use the quest log.
36 public method setDescription takes string description returns nothing
37 debug if (not thistype.useQuestLog) then
38 debug call this.print("setDescription() was called (quest log is disabled).")
39 debug endif
40 set this.m_description = description
41 call QuestSetDescription(this.m_questLogQuest, description)
42 endmethod
43
44 public method description takes nothing returns string
45 return this.m_description
46 endmethod
47
48 //members
49
50 /// Used by AQuestItem, do not use.
51 public method questLogQuest takes nothing returns quest
52 return this.m_questLogQuest
53 endmethod
54
55 //methods
56
57 public stub method setState takes integer state returns nothing
58 local integer i
59 local player user
60 local playercolor playerColor
61 local string title
62 call super.setState(state)
63 if (state == AAbstractQuest.stateCompleted or state == AAbstractQuest.stateFailed) then
64 set i = 0
65 loop
66 exitwhen (i == this.m_questItems.size())
67 if (AQuestItem(this.m_questItems[i]).state() == AAbstractQuest.stateNew) then
68 call AQuestItem(this.m_questItems[i]).setState(state)
69 endif
70 set i = i + 1
71 endloop
72 endif
73 if (thistype.useQuestLog) then
74 if (this.character() == 0) then
75 set title = this.title()
76 else
77 set user = this.character().user()
78 set playerColor = GetPlayerColor(user)
79 set title = "|cff" + PlayerColorToString(playerColor) + this.title() + "|r"
80 set user = null
81 set playerColor = null
82 endif
83 call QuestSetTitle(this.m_questLogQuest, title)
84 //call QuestSetDescription(this.questLogQuest, this.description)
85 if (state == AAbstractQuest.stateNotUsed) then
86 call QuestSetDiscovered(this.m_questLogQuest, false)
87 elseif (state == AAbstractQuest.stateNew) then
88 call QuestSetDiscovered(this.m_questLogQuest, true)
89 call FlashQuestDialogButton()
90 call ForceQuestDialogUpdate() //required?
91 elseif (state == AAbstractQuest.stateCompleted) then
92 call QuestSetCompleted(this.m_questLogQuest, true)
93 call FlashQuestDialogButton()
94 call ForceQuestDialogUpdate() //required?
95 elseif (state == AAbstractQuest.stateFailed) then
96 call QuestSetFailed(this.m_questLogQuest, true)
97 call FlashQuestDialogButton()
98 call ForceQuestDialogUpdate() //required?
99 endif
100 endif
101 endmethod
102
103 public method displayUpdateMessage takes string message returns nothing
104 local player user = this.character().user()
105 call DisplayTimedTextToPlayer(user, 0.0, 0.0, 20.0, this.title())
106 call DisplayTimedTextToPlayer(user, 0.0, 0.0, 20.0, message)
107 call PlaySoundPathForPlayer(user, thistype.updateSoundPath)
108 set user = null
109 endmethod
110
111 //Wenn alle QuestItems den gleichen State haben, erhält das Quest ebenfalls diesen State
112 public method checkQuestItemsForState takes integer state returns boolean
113 local integer i
114 local boolean result = true
115 //Hat noch nicht den State
116 if (this.state() != state) then
117 set i = 0
118 loop
119 exitwhen(i == this.m_questItems.size())
120 if (AQuestItem(this.m_questItems[i]).state() != state) then
121 set result = false
122 endif
123 set i = i + 1
124 endloop
125 if (result) then
126 call this.setState(state)
127 endif
128 endif
129 return result
130 endmethod
131
132 /// Friend relationship to @struct AQuestItem, do not use.
133 public method addQuestItem takes AQuestItem questItem returns integer
134 call this.m_questItems.pushBack(questItem)
135 return this.m_questItems.backIndex()
136 endmethod
137
138 /// Friend relationship to @struct AQuestItem, do not use.
139 public method removeQuestItemByIndex takes integer index returns nothing
140 call this.m_questItems.erase(index)
141 endmethod
142
143 private method createQuestLogQuest takes nothing returns nothing
144 if (thistype.useQuestLog) then
145 set this.m_questLogQuest = CreateQuest()
146 call QuestSetDiscovered(this.m_questLogQuest, false) //hide quest before setting state
147 call QuestSetRequired(this.m_questLogQuest, this.character() == 0)
148 endif
149 endmethod
150
151 public static method create takes ACharacter character, string title returns thistype
152 local thistype this = thistype.allocate(character, title)
153 //dynamic members
154 set this.m_questItems = AIntegerVector.create()
155
156 call this.createQuestLogQuest()
157 return this
158 endmethod
159
160 private method destroyQuestLogQuest takes nothing returns nothing
161 if (thistype.useQuestLog) then
162 call DestroyQuest(this.m_questLogQuest)
163 set this.m_questLogQuest = null
164 endif
165 endmethod
166
167 //Alle QuestItems werden auch zerstört
168 private method destroyQuestItems takes nothing returns nothing
169 loop
170 exitwhen (this.m_questItems.empty())
171 call AQuestItem(this.m_questItems.back()).destroy()
172 endloop
173 call this.m_questItems.destroy()
174 endmethod
175
176 public method onDestroy takes nothing returns nothing
177 call this.destroyQuestLogQuest()
178 call this.destroyQuestItems()
179 endmethod
180
181 //init is already used
182 public static method init0 takes boolean useQuestLog, string updateSoundPath returns nothing
183 //static start members
184 set thistype.useQuestLog = useQuestLog
185 set thistype.updateSoundPath = updateSoundPath
186 endmethod
187
188 //static start members
189
190 //AQuestItem need access
191 public static method isQuestLogUsed takes nothing returns boolean
192 return thistype.useQuestLog
193 endmethod
194 endstruct
195
196 endlibrary